import { LoginState } from '@/pages/LoginAndRegister/components/Login/interface';
import {
    RegisterResponse,
    RegisterState,
} from '@/pages/LoginAndRegister/components/Register/interface';
import request from './index';
import { UserInfoWithTokenState, UserInfoState } from '../store/user/interface';

export function login(state: LoginState): Promise<RD<UserInfoWithTokenState>> {
    return request.post('/login', {
        data: { ...state },
    });
}

export function register(state: RegisterState): Promise<RD<RegisterResponse>> {
    return request.post('/register', {
        data: { ...state },
    });
}

export function fetchUserInfo(): Promise<RD<UserInfoState>> {
    return request.get('/getUser');
}
